<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>






<html lang="zh-cn">
<head>
	 <base href="<%=basePath%>">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title>登录</title>  
    <script type="text/javascript">
		var cur_path = "<%=request.getContextPath() %>";
	</script>
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/pintuer.css">
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/admin.css">
    <script src="<%=request.getContextPath() %>/js/jquery.js"></script>
    <script src="<%=request.getContextPath() %>/js/pintuer.js"></script> 
    	<script type="text/javascript">
		window.onload=function(){
			window.document.onkeydown=function(e){
			try{
				if(event.keyCode){
					if(event.keyCode==13){
	                	document.getElementById("btn_login").click();   
	                	return false;
	                }
				}
			}catch(e){}
			try{
				if(e.which){
					if(e.which ==13){
	                	document.getElementById("btn_login").click();   
	                	return false;
	                }
				}
			}catch(e){}
			};
		
			$('#imageCode').bind('click', function(){ 
				var ls_url = cur_path + "/login.do?method=getImg&data="+new Date();
		        $("#imageCode").removeAttr("src"); //去除
		        $("#imageCode").attr("src",ls_url);
		     }); 
		};
		function checkAccount(){
			var userid = $("#userid").val();
			if(userid==""){
				$("#error_msg").text("用户名不能为空！");
				$("#userid").focus();
				return false;
			}
			var password = $("#password").val();
			if(password==""){
				$("#error_msg").text("密码不能为空！");
				$("#password").focus();
				return false;
			}
			var code = $("#code").val();
			if(code==""){
				$("#error_msg").text("验证码不能为空！");
				$("#code").focus();
				return false;
			}
			var ls_url = cur_path + "/login.do?method=checkCode&code="+code;
			$.post(ls_url,function(data){
				data = eval("["+data+"]");
				var return_code = data[0].return_code;
				if(return_code=='ok'){
					$.get( cur_path + "/login.do?method=login&userId="+$("#userid").val()+"&passWord="+$("#password").val()+"&d="+new Date(),function (data1){
						data = eval("["+data1+"]");
						return_code = data[0].return_code;
						if(return_code!='ok'){
							$("#error_msg").html("用户名密码错误！");
						}else{
							window.location.href=cur_path + "/index.jsp";
						}
					});
				}else{
					$("#error_msg").html("验证码错误");
					$("#code").focus();
					return  false;
				}
			});
		}
		
		function login(){
			checkAccount();
		}
		
	</script> 
</head>
<body>
<div class="bg"></div>
<div class="container">
    <div class="line bouncein">
        <div class="xs6 xm4 xs3-move xm4-move">
            <div style="height:150px;"></div>
            <div class="media media-y margin-big-bottom">           
            </div>         
            <form name="form1" action="index.html" method="post">
            <div class="panel loginbox">
                <div class="text-center margin-big padding-big-top"><h1>在线烹饪系统</h1></div>
                <div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
                    <div class="form-group">
                        <div class="field field-icon-right">
                            <input type="text" class="input input-big" name="userid" id="userid" placeholder="登录账号" data-validate="required:请填写账号" />
                            <span class="icon icon-user margin-small"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="field field-icon-right">
                            <input type="password" class="input input-big" name="password" id="password" placeholder="登录密码" data-validate="required:请填写密码" />
                            <span class="icon icon-key margin-small"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="field">
                            <input type="text" class="input input-big" name="code" id="code" placeholder="填写右侧的验证码" data-validate="required:请填写右侧的验证码" />
                           <img src="<%=request.getContextPath() %>/login.do?method=getImg" alt="" width="100" height="32" class="passcode" style="height:43px;cursor:pointer;" onclick="this.src=this.src+'?'">  
                                                   
                        </div>
                    </div>
                </div>
                <div style="padding:30px;">
                <input type="button" onclick="login()"  style="width: 130px" class="button bg-main text-big input-big" value="登录">
                <input type="button" onclick="window.location.href='<%=request.getContextPath() %>/Users.jsp?sign=sign'"  style="width: 130px" class="button bg-main text-big input-big" value="注册">
                </div>
                <div style="padding:30px;">
                <span style="color: red;" id="error_msg"><%=request.getAttribute("Usersmsg")==null?"":request.getAttribute("Usersmsg").toString() %></span>
                </div>
            </div>
            </form>          
        </div>
    </div>
</div>

</body>
</html>
